package com.taxigang.client.uibinder_mobile;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.jquery.mobile.ui.Button;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.Widget;
import com.taxigang.client.micro.TaxiGangCreator;


public class AlertOkCancelMobile extends Composite {

	private static AlertOkCancelMobileUiBinder uiBinder = GWT
	.create(AlertOkCancelMobileUiBinder.class);

	interface AlertOkCancelMobileUiBinder extends UiBinder<Widget, AlertOkCancelMobile> {
	}


	private PopupPanel popupPandel = new PopupPanel(false,true);

	@UiField
	Button okButton;
	@UiField
	Button cancelButton;
	@UiField
	Label alertText;

	public AlertOkCancelMobile(final Command cmd,String title, String text, boolean showCancel) {
		initWidget(uiBinder.createAndBindUi(this));
		okButton.setText("OK");
		cancelButton.setText(TaxiGangCreator.taxiGangConstants.cancel());

		popupPandel.setGlassEnabled(true);
		popupPandel.setTitle(title);
//		popupPandel.setHTML("<p><b>"+title+"</b></p>");

		popupPandel.setWidget(this);
		alertText.setText(text);

		okButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				if (cmd != null){
					cmd.execute();
				}
				popupPandel.hide();
			}
		});
		cancelButton.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				popupPandel.hide();

			}
		});

		cancelButton.setVisible(showCancel);

	}


	public void show(){
		popupPandel.center();

		popupPandel.show();
	}

}
